<?php
class Model_Guest extends Df_Model{
	

	private $user_id;
	public function __construct($id = null) {
		$this->user_id = $id;
		parent::__construct(new Model_DbTable_Guests(), $id);
	}
	
	public function getGuestsListMain($user_id) {
		return $this->_dbTable->fetchAll(
			$this->_dbTable->select()
				->where('user_id = ?', $user_id)
				->where('visited = ?', '0')
				->order('id DESC')
				->group("friend_id")
				->limit(20,0)
			);
	}
	
	public function getGuests($user_id, $page) {
		return $this->_dbTable->fetchAll(
			$this->_dbTable->select()
				->where('user_id = ?', $user_id)
				->order('id DESC')
				->limitPage($page, 20)
			);
	}
	
	public function setVisited($user_id, $friend_id) {
		$data = array(
			'visited' => '1'
		);

		$this->_dbTable->update($data, array('user_id = ?'=> $user_id,'friend_id = ?'=> $friend_id));
		
	}
	
	public function setAllVisited($user_id) {
		$data = array(
			'visited' => '1'
		);

		$this->_dbTable->update($data, array('user_id = ?'=> $user_id));
		
	}

}